package com.sjb.sixteen_journey_backend.config;

import jakarta.servlet.http.HttpSession;
import jakarta.websocket.HandshakeResponse;
import jakarta.websocket.server.HandshakeRequest;
import jakarta.websocket.server.ServerEndpointConfig;

/**
 * @version v1.0
 * @ClassName: GetHttpSessionConfig
 * @Description: TODO(一句话描述该类的功能)
 * @Author: 黑马程序员
 */
public class GetHttpSessionConfig extends ServerEndpointConfig.Configurator {

    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        try {
            //获取HttpSession对象
            HttpSession httpSession = (HttpSession) request.getHttpSession();
            //将httpSession对象保存起来
            sec.getUserProperties().put(HttpSession.class.getName(),httpSession);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
